<template>
  <div class="container">
    <div class="noAccount" v-show="noAccount">
      <el-row class="noDataInfo">
        <img src="../../../static/img/noDataInfo.png" alt />
      </el-row>
      <el-row class="payOffInfoCancel">
        <p>尚未设置工资专户</p>
      </el-row>
    </div>
    <div v-show="yesAccount" class="mainCon">
      <el-row style="position: relative; padding: 0 24px">
        <div class="runWater">流水明细</div>
        <div
          v-if="tipsInfo"
          class="tipsInfo"
          style="
            position: absolute;
            left: 90px;
            top: 33px;
            color: #ff4d4a;
            font-size: 14px;
          "
        >
          {{ tipsInfo }}
        </div>
      </el-row>
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="时间" class="row-padding-bottom">
              <el-date-picker
                v-model="filterField.time"
                type="date"
                placeholder="请选择"
                :picker-options="pickerOptions"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="同步状态" class="row-padding-bottom">
              <el-select
                v-model="filterField.status"
                filterable
                placeholder="请选择"
                clearable
              >
                <el-option label="未同步" value="0"></el-option>
                <el-option label="已同步" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="类型" class="row-padding-bottom">
                <el-select
                  v-model="filterField.operate"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option label="支出" value="OUT"></el-option>
                  <el-option label="缴存" value="IN"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <el-form-item>
            <a
              @click="toggleAdvanced"
              style="margin-left: 40px; color: #409eff; cursor: pointer"
              class="btnColor"
            >
              {{ advanced ? '收起' : '展开' }}
              <i
                :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
              ></i>
            </a>
            <el-button
              type="primary"
              icon="icon iconfont iconchazhao1"
              @click="searchList"
              class="searchBtn"
            >
              <span>搜索</span>
            </el-button>
          </el-form-item>
          <!-- <div style="display:inline-block" v-if="userType=='BANK' && bankAcountImport">
            <div class="uploadBox">
              <el-button round type="primary" class="createSalaryBut" @click = "isImport" v-if = "isShowImport == 1">导入</el-button>
              <el-button round type="primary" class="createSalaryBut" v-if = "isShowImport == 0">导入</el-button>
              <div class="upLoadDom"  v-if = "isShowImport == 0">
                <form id="waterImportBox">
                  <input
                    type="file"
                    id="waterImportExcel"
                    name="multipartFile"
                    @change="waterImportfileChange"
                  />
                </form>
              </div>
              <el-link type="primary" @click="downLoad()" class="uploadBtn">流水导入模板下载</el-link>
            </div>
          </div> -->
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <div class="proDetailsListBox">
          <div
            class="colSetupBottom"
            v-if="userType == 'BANK' && bankAcountImport"
          >
            <el-button
              class="commonBut saveBtn funComBut"
              @click="isImport"
              v-if="isShowImport == 1"
            >
              <span class="opetareText">导入</span>
            </el-button>
            <el-button
              class="commonBut saveBtn funComBut"
              v-if="isShowImport == 0"
              @click="goFile"
            >
              <span class="opetareText">导入</span>
            </el-button>
            <div
              class="upLoadDom"
              v-if="isShowImport == 0"
              style="display: none"
            >
              <form id="waterImportBox">
                <input
                  type="file"
                  ref="files"
                  id="waterImportExcel"
                  name="multipartFile"
                  @change="waterImportfileChange"
                />
              </form>
            </div>
            <div style="display: inline-block">
              <el-link type="primary" @click="downLoad()" class="uploadBtn"
                >流水导入模板下载</el-link
              >
            </div>
          </div>
          <el-table
            ref="tableBox1"
            :max-height="tableHeight"
            :data="salaryAccountList"
            v-loading="loading"
            :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
            highlight-current-row
            stripe
            style="border: 1px solid #dfe6ec"
          >
            <el-table-column
              prop="createTime"
              label="时间"
              align="center"
              :formatter="formatTd"
              width="175px"
            ></el-table-column>
            <el-table-column
              prop="journal"
              label="金额(元)"
              align="center"
              :formatter="formatTd"
            ></el-table-column>
            <el-table-column
              prop="operate"
              label="类型"
              align="center"
              :formatter="formatTd"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.operate == 'IN'">缴存</span>
                <span v-else>支出</span>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="remark" label="备注" align="center" :formatter="formatTd"></el-table-column> -->
            <el-table-column label="备注" width="230">
              <template slot-scope="scope">
                <copyText
                  :tableIndex="scope.$index"
                  :copyTextName="scope.row.remark"
                  :columnName="'remark'"
                ></copyText>
              </template>
            </el-table-column>
            <el-table-column
              prop="status"
              label="同步状态"
              align="center"
              :formatter="formatTd"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.status == '0'">未同步</span>
                <span v-else>已同步</span>
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              v-if="userType == 'BANK' && bankAcountImport"
              align="center"
              :formatter="formatTd"
              width="200"
              fixed="right"
            >
              <template slot-scope="scope">
                <el-link type="primary" @click="deleteSalary(scope.row)"
                  >删除</el-link
                >
                <el-link
                  v-if="scope.row.status == '0'"
                  type="primary"
                  @click="toSyncSalary(scope.row)"
                  >手动同步</el-link
                >
              </template>
            </el-table-column>

            <!-- 表格数据为空时，页面显示 -->
            <div slot="empty" v-show="isShow">
              <emptyTable emptyText="暂无相关工资专户数据"></emptyTable>
            </div>
          </el-table>
          <Pagination
            ref="pagination"
            @getList="getTableList"
            :filterField="filterField"
            :requestUrl="requestUrl"
          ></Pagination>
        </div>
      </div>
    </div>
    <el-dialog
      title="修改工资专户信息"
      :visible.sync="accountFormVisible"
      :close-on-click-modal="false"
      @close="cancelAccountDialog('accountForm')"
      custom-class="brand-dialog-min-width"
      :modal-append-to-body="false"
    >
      <el-form :model="accountForm" :rules="formRules" ref="accountForm">
        <el-form-item label="项目名称" prop="projectId" label-width="135px">
          <el-select
            v-model="accountForm.projectId"
            placeholder="请选择"
            class="optionWidth"
            clearable
            filterable
            disabled
          >
            <el-option
              v-for="(item, index) of projectListOptions"
              :key="index"
              :label="item.name"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开户银行" prop="bankId" label-width="135px">
          <el-select
            v-model="accountForm.bankId"
            placeholder="请选择"
            class="optionWidth"
            clearable
            filterable
            :disabled="accountForm.projectTotal > 0"
            @change="changeBankId"
          >
            <el-option
              v-for="(item, index) of bankData"
              :key="index"
              :label="item.name"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="银行网点" prop="bankSiteId" label-width="135px">
          <el-select
            v-model="accountForm.bankSiteId"
            class="optionWidth"
            :placeholder="
              accountForm.bankId != '' ? '请选择' : '请先选择开户银行'
            "
            clearable
            filterable
          >
            <el-option
              v-for="(item, index) of bankBranchOptions"
              :key="index"
              :label="item.name"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="专户账号" prop="account" label-width="135px">
          <el-input
            v-model="accountForm.account"
            autocomplete="off"
            placeholder="请输入"
            class="inputWidth"
            @blur="accountForm.account = changeValue($event)"
          ></el-input>
        </el-form-item>
        <el-form-item label="专户开户凭证" label-width="135px">
          <div class="uploadBox">
            <el-button round class="uploadImg">上传</el-button>
            <span class="uploadImgState"
              >仅支持png，jpg，jpeg格式的图片，大小2MB</span
            >
            <div class="upLoadDom">
              <form id="salaryExcelForm">
                <input
                  type="file"
                  id="salaryExcel"
                  name="file"
                  @change="fileChange('1')"
                />
              </form>
            </div>
          </div>
        </el-form-item>
        <el-row>
          <el-col :span="24">
            <ul class="clearfix imgStyle">
              <li
                class="fl"
                v-for="(item, index) of accountForm.uploadFile"
                :key="index"
              >
                <el-image
                  style="width: 100px; height: 100px"
                  :src="item.url"
                  :preview-src-list="accountForm.srcList"
                  @click="enlargeImg('1', index)"
                ></el-image>
                <i
                  class="icon iconfont iconjian"
                  @click="delFile('1', index)"
                ></i>
              </li>
            </ul>
          </el-col>
        </el-row>
        <el-form-item
          label="农民工工资委托发放三方协议"
          label-width="135px"
          class="AgreementBox"
        >
          <div class="uploadBox">
            <el-button round class="uploadImg">上传</el-button>
            <span class="uploadImgState"
              >仅支持png，jpg，jpeg格式的图片，大小2MB</span
            >
            <div class="upLoadDom">
              <form id="ExcelAgreement">
                <input
                  type="file"
                  id="salaryExcelAgr"
                  name="file"
                  @change="fileChange('2')"
                />
              </form>
            </div>
          </div>
        </el-form-item>
        <el-row>
          <el-col :span="24">
            <ul class="clearfix imgStyle">
              <li
                class="fl"
                v-for="(item, index) of accountForm.upLoadAgreementFile"
                :key="index"
              >
                <el-image
                  style="width: 100px; height: 100px"
                  :src="item.url"
                  :preview-src-list="accountForm.agrSrcList"
                  @click="enlargeImg('2', index)"
                ></el-image>
                <i
                  class="icon iconfont iconjian"
                  @click="delFile('2', index)"
                ></i>
              </li>
            </ul>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          @click.native="cancelAccountDialog('accountForm')"
          class="cancel"
          >取消</el-button
        >
        <el-button
          type="primary"
          @click.native="saveBankInfo('accountForm')"
          class="save"
          :loading="canLogin"
          >保存</el-button
        >
      </div>
    </el-dialog>
    <el-dialog
      title="上传失败"
      :visible.sync="formVisible"
      :close-on-click-modal="false"
      @close="closeDialog"
      custom-class="dialog-minwidth"
      :modal-append-to-body="false"
    >
      <div class="errorNoticeBox">
        <i class="icon iconfont iconshibai1"></i>
      </div>
      <div v-html="errorNotice" class="errorBox"></div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click.native="closeDialog" class="save"
          >确认</el-button
        >
        <el-button @click.native="closeDialog" class="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import emptyTable from '@/components/publicCom/emptyTable'
import Pagination from '@/components/publicCom/pagination'
import common from '../../kits/common'
export default {
  name: 'czSalarySpecialAccount',
  props: ['projectId', 'accountCode', 'bankId'],
  components: {
    emptyTable,
    Pagination,
  },
  data() {
    return {
      hiddleToolBar: false,
      tableHeight: null,
      noAccount: false,
      yesAccount: false,
      loading: true,
      isShow: false, //列表加载
      //表格数据
      salaryAccountList: [],
      advanced: false,
      requestUrl: 'api-acc/journalmiddle/base/journalmiddlelist',
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        },
      },
      filterField: {
        time: '',
        accountCode: '',
        bankId: '',
        operate: '',
        status: '',
      },
      path: '',
      bankName: '', //专户银行
      bankSiteName: '', //银行网点名称
      account: '', //专户账号
      balance: '', //专户余额
      payTotal: '', //专户总缴纳
      expensesTotal: '', //专户总支出
      accountFormVisible: false, //是否显示补充专户弹框
      canLogin: false, //专户保存按钮loading
      // 补充专户信息
      accountForm: {
        accountId: '',
        bankId: '',
        account: '',
        uploadFile: [], //
        srcList: [],
        oldSrcList: [],
        upLoadAgreementFile: [], //三方协议
        agrSrcList: [],
        oldAgrSrcList: [],
        projectId: '',
        bankSiteId: '', //银行网点id
      },
      bankData: [],
      formRules: {
        projectId: [
          {
            required: true,
            message: '项目名称不能为空',
            trigger: 'change',
          },
        ],
        bankId: [
          {
            required: true,
            message: '银行不能为空',
            trigger: 'change',
          },
        ],
        account: [
          {
            required: true,
            // pattern: /^([1-9]{1})(\d{11,18})((-)(\d{1,9}))*$/,
            pattern: /^[^\u4e00-\u9fa5]{0,}$/,
            message: '请输入正确格式的账号',
            trigger: 'blur',
          },
        ],
        bankSiteId: [
          {
            required: true,
            message: '银行网点不能为空',
            trigger: 'change',
          },
        ],
      },
      formVisible: false,
      errorNotice: '',
      flieUpload: {
        // bankAccount: "",
        projectId: '',
      },
      bankBranchOptions: [], //网点列表
      projectListOptions: [],
      tipsInfo: '',
      resourceOptions: [],
      typeDescOptions: [],
      userType: '',
      bankAcountImport: false,
      isShowImport: '',
    }
  },
  activated() {
    window.addEventListener('scroll', this.handleScroll, true)
    this.$nextTick(function () {
      this.$refs.tableBox1.doLayout()
    })
  },
  deactivated() {
    let that = this
    window.removeEventListener('scroll', that.handleScroll, true)
  },
  beforeDestroy() {
    let that = this
    window.removeEventListener('scroll', that.handleScroll, true)
  },
  mounted() {
    if (this.$route.query.projectId) {
      this.flieUpload.projectId = this.$route.query.projectId
    }
    this.filterField.accountCode = this.accountCode
    this.filterField.bankId = this.bankId
    this.getAcountInfo()
    this.getProjectList()

    //加载银行列表
    this.getBankList()
    this.userType = this.$store.state.userType
    this.getBankAcountdetail()
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    window.addEventListener('scroll', this.handleScroll, true)
    let that = this
    this.$nextTick(function () {
      let tableHeightCur = this.$refs.tableBox1.$el.clientHeight
      let tableTop = this.$refs.tableBox.getBoundingClientRect().top
      this.tableHeight = window.innerHeight - 440
      // if(tableHeightCur + tableTop > window.innerHeight){
      //     this.tableHeight = this.$refs.mainCon.getBoundingClientRect().height - 86
      // }else{
      //     document.getElementsByClassName('tableBoxCur').length&&(document.getElementsByClassName('tableBoxCur')[0].style.height = window.innerHeight - tableTop - 40 + 'px')
      // }

      window.onresize = function () {
        if (!that.$refs.tableBox1) {
          return
        }
        let tableHeightCur = that.$refs.tableBox1.$el.clientHeight
        let tableTop = that.$refs.tableBox.getBoundingClientRect().top
        this.tableHeight = window.innerHeight - 440
        // if(tableHeightCur + tableTop > window.innerHeight){
        //     that.tableHeight = that.$refs.mainCon.getBoundingClientRect().height - 86
        // }else{
        //     document.getElementsByClassName('tableBoxCur').length&&(document.getElementsByClassName('tableBoxCur')[0].style.height = window.innerHeight - tableTop - 40 + 'px')
        // }
      }
    })
  },
  methods: {
    /**
     * @description: 点击上传文件触发input文件
     */
    goFile() {
      this.$refs.files.click()
    },
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    handleScroll(e) {
      this.$nextTick(function () {
        //变量scrollTop是滚动条滚动时，距离顶部的距离
        var scrollTop = e.target.scrollTop
        if (
          this.$refs.tableBox &&
          this.$refs.tableBox.getBoundingClientRect().top < 128
        ) {
          this.tableHeight = window.innerHeight - 240
          if (document.getElementsByClassName('tableBoxCur').length) {
            document.getElementsByClassName('tableBoxCur')[0].style.height =
              null
          }
          this.hiddleToolBar = true
        } else {
          this.hiddleToolBar = false
        }
      })
    },
    changeBankId(val) {
      this.accountForm.bankSiteId = ''
      if (!val) {
        this.bankBranchOptions = []
      } else {
        this.getBankBranchList(val)
      }
    },
    getBankBranchList(bankId) {
      this.axios
        .post('api-acc/accountbank/expand/banksite', { bankId })
        .then((res) => {
          this.bankBranchOptions = res.data.result
          if (res.data.result.length === 0) {
            this.$message({
              message: '请联系银行管理员进行网点信息维护',
              type: 'warning',
            })
          }
        })
        .catch((error) => {
          this.$message({
            message: '获取网点数据失败',
            type: 'error',
          })
        })
    },
    getProjectList() {
      this.axios({
        method: 'post',
        url: 'api-p/projectcompany/expand/current/projects',
      })
        .then((response) => {
          this.projectListOptions = response.data.result
        })
        .catch((error) => {
          console.log(error)
        })
    },
    getAcountInfo() {
      var url = 'api-acc/account/expand/accountdetail'
      this.axios({
        method: 'post',
        url: url,
        data: {
          projectId: this.projectId,
        },
      })
        .then((response) => {
          if (!response.data.hasError) {
            var data = response.data.result
            if (!data.account) {
              this.noAccount = true
            } else {
              this.yesAccount = true
            }
            this.bankName = data.bankName
            this.bankSiteName = data.bankSiteName ? data.bankSiteName : ''
            this.account = data.account
            this.balance = data.balance
            this.payTotal = data.payTotal
            this.expensesTotal = data.expensesTotal
            if (this.isYcUser() && this.balance * 1 < 0) {
              this.tipsInfo =
                '流水数据不完整，请联系施工企业登录系统及时分配流水。'
            } else {
              this.tipsInfo = ''
            }
            this.isShowImport = data.isCancellation
          }
        })
        .catch((error) => {
          this.$message.error('专户数据获取失败')
        })
    },
    getTableList(data) {
      this.salaryAccountList = data
      this.loading = false
      if (this.salaryAccountList.length < 1) {
        this.isShow = true
      }
    },
    searchList() {
      this.$refs.pagination.getTableListData()
    },
    //获取修改专户的信息
    getUpdateAccountInfo() {
      this.axios({
        method: 'post',
        url: 'api-acc/account/expand/accountdetail',
        data: {
          projectId: this.projectId,
        },
      })
        .then(
          (res) => {
            if (!res.data.hasError) {
              this.accountForm.projectId = this.projectId
              this.accountForm.bankId = res.data.result.bankId
              this.accountForm.accountId = res.data.result.id
              this.accountForm.account = res.data.result.account
              this.accountForm.bankSiteId = res.data.result.bankSiteId
                ? res.data.result.bankSiteId == 0
                  ? ''
                  : res.data.result.bankSiteId
                : ''
              if (res.data.result.openCertificateFiles.length > 0) {
                this.accountForm.uploadFile =
                  res.data.result.openCertificateFiles
                for (var i = 0; i < this.accountForm.uploadFile.length; i++) {
                  this.accountForm.srcList.push(
                    this.accountForm.uploadFile[i].url
                  )
                  this.accountForm.oldSrcList.push(
                    this.accountForm.uploadFile[i].url
                  )
                }
              }
              if (res.data.result.agreementFiles.length > 0) {
                this.accountForm.upLoadAgreementFile =
                  res.data.result.agreementFiles
                for (
                  var i = 0;
                  i < this.accountForm.upLoadAgreementFile.length;
                  i++
                ) {
                  this.accountForm.agrSrcList.push(
                    this.accountForm.upLoadAgreementFile[i].url
                  )
                  this.accountForm.oldAgrSrcList.push(
                    this.accountForm.upLoadAgreementFile[i].url
                  )
                }
              }
              this.getBankBranchList(res.data.result.bankId)
            } else {
              this.$message({
                message: res.data.errorMsg,
                type: 'error',
              })
            }
          },
          (res) => {
            this.$message({
              message: '获取专户信息失败',
              type: 'error',
            })
          }
        )
        .catch((error) => {})
    },
    //修改专户
    updateAccount() {
      this.accountFormVisible = true
      this.$nextTick(function () {
        this.getUpdateAccountInfo()
      })
    },
    cancelAccountDialog() {
      this.accountFormVisible = false
      this.accountForm.srcList = []
      this.accountForm.oldSrcList = []
      this.accountForm.uploadFile = []
      this.accountForm.upLoadAgreementFile = []
      this.accountForm.agrSrcList = []
      this.accountForm.oldAgrSrcList = []
      this.$refs.accountForm.resetFields()
    },
    // 获取银行
    getBankList() {
      this.axios({
        method: 'post',
        data: { type: 'BANK_TYPE' },
        url: 'api-bs/base/dicitem/findbytype',
      })
        .then(
          (response) => {
            if (!response.data.hasError) {
              this.bankData = response.data.result
            } else {
            }
          },
          (response) => {}
        )
        .catch((error) => {})
    },
    //专户图片上传
    fileChange(type) {
      var Filedata
      var file
      var fileSize
      if (type == '1') {
        Filedata = $('#salaryExcel').val()
      } else {
        Filedata = $('#salaryExcelAgr').val()
      }
      if (!Filedata) {
        return
      }
      try {
        if (type == '1') {
          file = $('#salaryExcel')[0].files[0]
        } else {
          file = $('#salaryExcelAgr')[0].files[0]
        }
        fileSize = (file.size / 1024).toFixed(0)
      } catch (e) {
        this.$message({
          message:
            '您的浏览器暂不支持计算上传文件的大小，确保上传文件不要超过5M，建议使用FireFox、Chrome或IE10以上浏览器。',
          type: 'warning',
        })
      }
      // 文件大小和限制类型可以通过子组件传值区分，若不适应于使用页面，可自行判断
      if (type == '1') {
        if (this.accountForm.uploadFile.length == 20) {
          this.$message({
            message: '最多上传20个附件',
            type: 'warning',
          })
          $('#salaryExcel').val('')
          return
        }
      } else {
        if (this.accountForm.upLoadAgreementFile.length == 20) {
          this.$message({
            message: '最多上传20个附件',
            type: 'warning',
          })
          $('#salaryExcelAgr').val('')
          return
        }
      }
      if (fileSize / 1 > 1024 * 2) {
        this.$message({
          message: '最多能上传2M以内的图片',
          type: 'warning',
        })
        return
      }
      if (!/\.(png|jpg|jpeg|PNG|JPG|JPEG)$/.test(Filedata)) {
        this.$message({
          message: '仅支持上传png、jpg、jpeg格式文件',
          type: 'warning',
        })
        return
      }
      let that = this
      var options = {
        url: common.uploadUrl + 'api-f/files/upload',
        type: 'POST',
        dataType: 'json',
        success: function (data) {
          if (type == '1') {
            that.accountForm.uploadFile.push(data)
            that.accountForm.srcList.push(data.url)
            that.accountForm.oldSrcList.push(data.url)
            $('#salaryExcel').val('')
          } else {
            that.accountForm.upLoadAgreementFile.push(data)
            that.accountForm.agrSrcList.push(data.url)
            that.accountForm.oldAgrSrcList.push(data.url)
            $('#salaryExcelAgr').val('')
          }
        },
        error: function () {},
      }
      if (type == '1') {
        $('#salaryExcelForm').ajaxSubmit(options)
      } else {
        $('#ExcelAgreement').ajaxSubmit(options)
      }
      return false
    },
    delFile(type, index) {
      if (type == '1') {
        this.accountForm.uploadFile.splice(index, 1)
      } else {
        this.accountForm.upLoadAgreementFile.splice(index, 1)
      }
    },
    //专户图片放大
    enlargeImg(type, index) {
      if (type == '1') {
        this.accountForm.srcList = this.accountForm.oldSrcList
        var demo = this.accountForm.srcList
        var frontArr = demo.slice(0, index)
        var behindArr = demo.slice(index, demo.length)
        var list = behindArr.concat(frontArr)
        this.accountForm.srcList = list
      } else {
        this.accountForm.agrSrcList = this.accountForm.oldAgrSrcList
        var demo = this.accountForm.agrSrcList
        var frontArr = demo.slice(0, index)
        var behindArr = demo.slice(index, demo.length)
        var list = behindArr.concat(frontArr)
        this.accountForm.agrSrcList = list
      }
    },
    //保存专户信息
    saveBankInfo() {
      //确定按钮禁止点击
      this.canLogin = true
      this.$refs['accountForm'].validate((valid) => {
        if (valid) {
          let data = {
            projectId: this.projectId,
            id: this.accountForm.accountId,
            account: this.accountForm.account,
            bankId: this.accountForm.bankId,
            openCertificateFile: JSON.stringify(this.accountForm.uploadFile),
            agreementFile: JSON.stringify(this.accountForm.upLoadAgreementFile),
            bankSiteId: this.accountForm.bankSiteId, //新增银行网点地段
          }
          this.saveAccountAjax(data)
        } else {
          this.canLogin = false
          return false
        }
      })
    },
    //保存专户的ajax
    saveAccountAjax(data) {
      this.axios({
        method: 'post',
        url: 'api-acc/account/expand/update',
        data: data,
      })
        .then(
          (res) => {
            this.canLogin = false
            if (!res.data.hasError) {
              this.$message({
                message: '保存成功',
                type: 'success',
              })
              this.accountFormVisible = false //关闭弹窗
              this.getAcountInfo()
            } else {
              this.$message({
                message: res.data.errorMsg,
                type: 'error',
              })
            }
          },
          (res) => {
            this.canLogin = false
            this.$message({
              message: '数据请求失败',
              type: 'error',
            })
          }
        )
        .catch((error) => {
          this.canLogin = false
        })
    },
    // 流水导入 ------start
    waterImportfileChange(e) {
      var that = this
      var url = window.location.href
      var Filedata = $('#waterImportExcel').val()
      var files = e.target.files[0]
      if (!/\.(xls|xlsx)$/.test(Filedata)) {
        this.$message({
          message: 'excel类型必须是.xls,xlsx中的一种',
          type: 'warning',
        })
        return
      }

      setTimeout(function () {
        that.uploadFileByAjaxSubmit(
          'api-acc/journalmiddle/base/import',
          that.success,
          that.error
        )
      }, 500)
    },
    uploadFileByAjaxSubmit(url, successCallBack, errorCallBack) {
      const vm = this
      var token = localStorage.getItem('access_token')
      var options = {
        url: common.uploadUrl + url,
        type: 'POST',
        data: vm.flieUpload,
        headers: { Authorization: 'Bearer ' + token },
        contentType: false,
        processData: false,
        success: function (data) {
          $('#waterImportExcel').val('')
          successCallBack(data)
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $('#waterImportExcel').val('')
          errorCallBack(XMLHttpRequest, textStatus, errorThrown)
        },
      }

      //三种方式均可
      $('#waterImportBox').ajaxSubmit(options)
      return false
    },
    success(data) {
      if (!data.hasError) {
        this.$message({
          message: data.msg,
          type: 'success',
        })
        this.$nextTick(function () {
          this.$refs.pagination.getTableListData()
        })
      } else {
        this.errorNotice = data.errorMsg
        this.formVisible = true
      }
    },
    //根据状态码判断是否是401
    error(XMLHttpRequest, textStatus, errorThrown) {
      if (XMLHttpRequest.status === '401' || XMLHttpRequest.status === '403') {
        localStorage.setItem('access_token', '')
        localStorage.setItem('refresh_token', '')
        localStorage.setItem('userName', '')
        // 只有在当前路由不是登录页面才跳转
        if (router.currentRoute.path !== '/login/loginFirst') {
          router.replace({
            path: '/login/loginFirst',
          })
        }
        //清除tab栏数据
        this.$store.state.sliderBar = []
        localStorage.removeItem('sliderBar')
      } else {
        this.$message({
          message: '数据请求失败',
          type: 'warning',
        })
      }
    },
    closeDialog() {
      this.formVisible = false
    },
    // 流水导入 ------end
    // 流水导入模板下载
    downLoad() {
      window.location.href =
        common.commonApi +
        'api-acc/accass/expand/bankAccountTemplateDown?access_token=' +
        localStorage.getItem('access_token')
    },
    deleteSalary(row) {
      this.$confirm('是否确认删除此工资专户流水?', '删除工资专户流水', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.toDeleteSalary(row)
        })
        .catch(() => {})
    },
    toDeleteSalary(row) {
      this.axios({
        method: 'post',
        url: 'api-acc/journalmiddle/base/delete',
        data: {
          id: row.id,
        },
      })
        .then(
          (response) => {
            if (!response.data.hasError) {
              this.$message({
                message: '删除成功',
                type: 'success',
              })
              this.$refs.pagination.getTableListData()
            } else {
              this.$message({
                message: response.data.errorMsg,
                type: 'error',
              })
            }
          },
          (response) => {}
        )
        .catch((error) => {})
    },
    toSyncSalary(row) {
      if (this.isShowImport == 1) {
        this.$message({
          message: '该专户已销户，不可手动同步',
          type: 'warning',
        })
        return
      }
      this.$confirm('是否确认手动同步?', '同步工资专户流水', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.syncSalary(row)
        })
        .catch(() => {})
    },
    syncSalary(row) {
      this.axios({
        method: 'post',
        url: 'api-acc/journalmiddle/base/syncjournal',
        data: {
          id: row.id,
        },
      })
        .then(
          (response) => {
            if (!response.data.hasError) {
              this.$message({
                message: response.data.msg,
                type: 'success',
              })
              this.$refs.pagination.getTableListData()
            } else {
              this.$message({
                message: response.data.errorMsg,
                type: 'error',
              })
            }
          },
          (response) => {}
        )
        .catch((error) => {})
    },
    //专户流水
    getBankAcountdetail() {
      this.axios({
        method: 'post',
        url: 'api-m/paramconfig/findbyname',
        data: {
          name: 'bankAcountdetail',
        },
      })
        .then((res) => {
          if (!res.data.hasError) {
            if (res.data.result.value == '1') {
              this.bankAcountImport = true
            } else {
              this.bankAcountImport = false
            }
          } else {
            this.$message({
              type: 'error',
              message: response.data.errorMsg,
            })
          }
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '数据请求失败，请重试',
            type: 'error',
          })
        })
    },
    // 是否导入
    isImport() {
      this.$message({
        message: '该专户已销户，不可导入流水',
        type: 'warning',
      })
    },
  },
}
</script>
<style lang="less" scoped>
.container {
  .noAccount {
    padding-top: 60px;
    text-align: center;
    color: #666666;
    .noDataInfo {
      margin-top: 16px;
    }
  }
  .accountInfo {
    ul li {
      width: 415px;
      height: 200px;
      float: left;
      padding: 24px 33px;
      border: 1px solid #dee5f4;
      .balace {
        font-size: 24px;
      }
      .color999 {
        font-size: 14px;
      }
      .color333 {
        font-size: 14px;
        line-height: 34px;
      }
      &:first-child {
        background: #f5f7fb;
      }
      &:last-child {
        border-left: none;
        .botBorder {
          width: 100%;
          height: 1px;
          background: #dee5f4;
          margin: 26px 0;
        }
        .payoff div {
          width: 50%;
          float: left;
        }
      }
    }
  }
  .runWater {
    margin-top: 32px;
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: bold;
    border-bottom: 1px solid #dee5f4;
    height: 28px;
  }
  // 修改专户弹窗样式
  .uploadBox {
    position: relative;
    .uploadImg {
      width: 96px;
      height: 36px;
      padding: 0px;
      color: #009588;
      border: 1px solid #009588;
      cursor: pointer;
    }
    .upLoadDom {
      position: absolute;
      width: 96px;
      height: 36px;
      top: 0;
      left: 0;
      opacity: 0;
      line-height: 0px;
      form {
        input {
          width: 96px;
          height: 36px;
          line-height: 0px;
          cursor: pointer;
        }
      }
    }
  }
  .AgreementBox {
    /deep/label {
      line-height: 20px;
    }
  }
  .imgStyle {
    margin-left: 135px;
    li {
      position: relative;
      margin-right: 20px;
      margin-bottom: 20px;
      .iconjian {
        position: absolute;
        right: -6px;
        top: -10px;
        font-size: 20px;
        cursor: pointer;
      }
      .el-image {
        cursor: pointer;
      }
    }
  }
  .createSalaryBut {
    background: #009588;
    border: 1px solid #009588;
    padding: 10px 23px;
    margin-left: 12px;
    &:hover {
      opacity: 0.8;
    }
  }
  .errorNoticeBox {
    text-align: center;
    margin-bottom: 24px;
    i {
      color: red;
      font-size: 50px;
    }
  }
  .errorBox {
    line-height: 24px;
  }
}
@import '../../../static/css/filterArea.less';
.proDetailsListBox {
  background: #fff;
  text-align: right;
  .colSetupBottom {
    margin-bottom: 24px;
  }
}
</style>
